const path = require("path");
const {HOST, SWAGGER_BASEPATH, PORT} = process.env;
const description = "###### 响应体json结构\n" +
    "\n" +
    "```\n" +
    "{\n" +
    "  code: 0,//0代表成功，1代表失败\n" +
    "  message: error,//成功或者错误消息\n" +
    "  data: null//数据\n" +
    "}\n" +
    "```\n" +
    "\n" +
    "###### 额外错误描述\n" +
    "\n" +
    "```\n" +
    "// 第一种\n" +
    "{\n" +
    "  code: 0,\n" +
    "  message: \"参数错误\",//存在字段漏传\n" +
    "  data: null\n" +
    "}\n" +
    "\n" +
    "// 第二种\n" +
    "{\n" +
    "  code: 0,\n" +
    "  message: \"Not Server\",//请求地址存在问题\n" +
    "  data: null\n" +
    "}\n" +
    "\n" +
    "// 第三种\n" +
    "{\n" +
    "  code: -1,\n" +
    "  message: \"登录凭证失效\",//当前账户已注销或者token过期或者其他地方重新登录，但用的还是原来的token\n" +
    "  data: null\n" +
    "}\n" +
    "```\n" +
    "\n" +
    "###### token\n" +
    "\n" +
    "token有效期为2h，除去登录和注册接口以及公共接口，其它接口都需要token，token在每次请求时，放在请求头。\n" +
    "\n" +
    "用户登录时，服务端会将token以cookie的形式放在浏览器本地缓存中\n" +
    "\n" +
    "如果勾选了七天免登陆，cookie存储时间为七天\n" +
    "\n" +
    "退出登录时，服务端也会自动删除cookie\n" +
    "\n" +
    "```\n" +
    "fetch(url, {\n" +
    "  headers: {\n" +
    "    'Authorization': 'Bearer ' + token\n" +
    "  }\n" +
    "})\n" +
    "```\n" +
    "\n";
const swaggerOptions = {
    definition: {
        "swagger": "2.0",
        "info": {
            "title": "Friends api文档",
            "description": description,
            "version": "1.0.0"
        },
        // 服务
        "host": `${HOST}:${PORT}`,
        "basePath": SWAGGER_BASEPATH,
        // http版本
        "schemes": [
            "http",
            "https",
        ]
    },
    securityDefinitions:{
        BearerAuth:{
            type:"object",
            name:"Authorization",
            in:"header"
        }
    },
    apis: [path.join(`${__dirname}+../../routes/router/*.js`),path.join(`${__dirname}+../../routes/router/common/*.js`)]
}

module.exports = swaggerOptions
